/**
 *
 */
package jp.seraph.same.model;

import jp.seraph.jsmf.motion.BlankMotionSession;
import jp.seraph.jsmf.motion.DefaultMotion;
import jp.seraph.jsmf.motion.Motion;
import jp.seraph.jsmf.motion.MotionSession;

/**
 *
 */
public class DefaultMotionModel extends AbstractListedHierarchicalViewModel<MotionSessionModel> implements MotionModel {
    public DefaultMotionModel(String aName) {
        super(aName);
    }

    public DefaultMotionModel(String aName, Motion aMotion){
        this(aName);

        for (MotionSession tSession : aMotion) {
            MotionSessionModel tNewModel = null;
            if(tSession instanceof BlankMotionSession){
                tNewModel = new BlankMotionSessionModel(((BlankMotionSession)tSession).getStep());
            }else{
                tNewModel = new DefaultMotionSessionModel(tSession);
            }

            this.add(this.getChildCount(), tNewModel);
        }
    }

    /**
     * @see jp.seraph.same.model.MotionModel#toMotion()
     */
    public Motion toMotion() {
        DefaultMotion tMotion = new DefaultMotion();
        for (MotionSessionModel tSession : this) {
            tMotion.addSession(tSession.toSession());
        }

        return tMotion;
    }
}
